package mo.leetcode_hot;

public class L338 {

    public int[] countBits(int n) {
        int[] res = new int[n+1];
        int highBit = 0;
        for (int i = 1; i <= n; i++) {
            if ((i & (i-1)) == 0) {
                highBit = i;
            }
            res[i] = res[i-highBit] + 1;
        }
        return res;
    }


}
